//
//  HBReadSettingModel.m
//  HeartBeat
//
//  Created by karong on 2023/9/12.
//

#import "HBReadSettingModel.h"

@implementation HBReadSettingModel
- (NSString *)colorStr {
    return _colorStr?:@"#353535";
}
- (NSString *)fontName {
    return @"PingFang-SC-Regular";
}
- (NSInteger)font {
    return _font ?: 20;
}
- (NSInteger)lineSpacing {
    return _lineSpacing ?: 5;
}
- (CGFloat)firstLineHeadIndent {
    return _firstLineHeadIndent ?: 20;
}
- (CGFloat)paragraphSpacingBefore{
    return _paragraphSpacingBefore ?: 3.5;
}
- (CGFloat)paragraphSpacing {
    return _paragraphSpacing ?: 3.5;
}
- (HBReadColor)state {
    return _state ?: HBReadColor_Yellow;
}
- (HBBrowseType)browseState {
    return _browseState ?: HBBrowseType_Scroll;
}
- (CGFloat)brightness {
    return [[UIScreen mainScreen] brightness];
}
- (NSInteger)aiTime {
    return _aiTime > 0 ? _aiTime : 20;
}

// 直接添加以下代码即可自动完成
- (void)encodeWithCoder:(NSCoder *)aCoder {
    [self modelEncodeWithCoder:aCoder];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    return [self modelInitWithCoder:aDecoder];
}

- (id)copyWithZone:(NSZone *)zone {
    return [self modelCopy];
}

- (NSUInteger)hash {
    return [self modelHash];
}

- (BOOL)isEqual:(id)object {
    return [self modelIsEqual:object];
}

- (NSString *)description {
    return [self modelDescription];
}

///存入数据
+(void)saveData:(HBReadSettingModel *)model{
    NSData *data = [HBReadSettingModel archivedDataForData:model];
    [[NSUserDefaults standardUserDefaults]setObject:data forKey:@"PPReadModelKey"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

+ (NSData *)archivedDataForData:(id)data {
    NSData * resData = nil;
    @try {
        resData = [NSKeyedArchiver archivedDataWithRootObject:data];
    }
    @catch (NSException *exception) {
        NSLog(@"%s,%d,%@", __FUNCTION__, __LINE__, exception.description);
        resData = nil;
    }
    @finally {
        
    }
    return resData;
}

///读取数据
+(HBReadSettingModel *)showData {
    NSData * data = [[NSUserDefaults standardUserDefaults] objectForKey:@"PPReadModelKey"];
    if (data){
        return [HBReadSettingModel unarchiveForData:data];
    }
    return  [[HBReadSettingModel alloc]init];
}

+ (id)unarchiveForData:(NSData*)data {
    id resObj = nil;
    @try {
        resObj = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    }
    @catch (NSException *exception) {
        NSLog(@"%s,%d,%@", __FUNCTION__, __LINE__, exception.description);
        resObj = nil;
    }
    @finally {
        
    }
    return resObj;
}
@end
